package com.one.blocks.rbac.jetcache;

import com.alicp.jetcache.CacheValueHolder;
import com.alicp.jetcache.support.AbstractValueDecoder;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author linfuxin Created on 2022-02-14 14:13:20
 */
public class JacksonValueDecoder extends AbstractValueDecoder {

    private final ObjectMapper objectMapper;

    public JacksonValueDecoder(ObjectMapper objectMapper) {
        super(false);
        this.objectMapper = objectMapper;
    }

    @Override
    protected Object doApply(byte[] buffer) throws Exception {
        return objectMapper.readValue(buffer, CacheValueHolder.class);
    }
}